package com.ddzj.scaffold.utils;

import org.bouncycastle.crypto.digests.SM3Digest;
import org.bouncycastle.util.encoders.Hex;

/**
 * @Author:yangzibo
 * @CreateTime:2024-05-12 19:39
 * @Description:
 * @Version:1.0
 **/
public class SM3Utils {
    public static String sm3(String input) {
        byte[] inputBytes = input.getBytes();
        SM3Digest digest = new SM3Digest();
        digest.update(inputBytes, 0, inputBytes.length);
        byte[] hashBytes = new byte[digest.getDigestSize()];
        digest.doFinal(hashBytes, 0);
        return Hex.toHexString(hashBytes);
    }

    public static void main(String[] args) {
        String message = "Hello, SM3!";
        String hash = sm3(message);
        System.out.println("SM3 Hash: " + hash);
    }
}
